<template>
	<view>
		<u--form :model="form" :rules="rules" ref="uForm">
			<u-form-item label="客户" prop="username" borderBottom @click="show = true" ref="item1"
				:customStyle="btnStyle1">
				<u--input v-model="form.name" disabled disabledColor="#ffffff" placeholder="请选择"
					suffixIcon="arrow-down"></u--input>
			</u-form-item>

			<u-form-item label="回访内容" prop="username" borderBottom ref="item1" :customStyle="btnStyle1">
				<u--textarea v-model="form.value1" placeholder="请输入内容" count></u--textarea>
			</u-form-item>
			
			

			<u-picker :show="show" :columns="list" keyName="nickname" @cancel="show = false"
				@confirm="confirm"></u-picker>
			<u-button @click="submit" color="#19BC9C">添加</u-button>
			<u-toast ref="uToast"></u-toast>
		</u--form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				rules: {
					'value1': {
						min: 3,
						required: true,
						message: '不低于3个字',
						trigger: ['change']
					},
				},
				btnStyle1: {
					marginLeft: "50px",
					width: '80%',
					label: "30px"
				},
				show: false,
				form: {
					name: '',
					id: '',
					value1: '',
				},
				list: [],
			}
		},
		onLoad(options) {
			
			this.formData()
		},
		onShow() {
			this.$u.auth.check()
			this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {};
		},
		methods: {
			submit() {

				this.$refs.uForm.validate().then(async (res) => {
					let result = await this.$u.api.business.VisitAdd({
						busid: this.form.id,
						adminid: this.LoginUser.id,
						content: this.form.value1,
					})
					if (result.code == 1) {
						this.$refs.uToast.show({
							type: 'success',
							message: result.msg,
							complete: () => {
								uni.navigateTo({
									url: '/pages/business/revisit/index'
								})
							}
						})
					}
					// console.log(this.form)
				}).catch(errors => {})
			},

			confirm({
				value
			}) {
				this.show = false
				this.form.name = value[0].nickname
				this.form.id = value[0].id
			},
			async formData() {
				let result = await this.$u.api.business.readdlist();
				if (result.code == 1) {

					this.list.push(result.data)
				}
			},
		}

	}
</script>